﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace COER
{
    static class Program
    {
        private static System.Threading.Mutex mutex;
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal;
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                mutex = new System.Threading.Mutex(true, "WaferAOI_Motion");
                if (mutex.WaitOne(0,false))
                {
                    Application.Run(new MainForm());
                    return;
                }
                else
                {
                    DialogResult dr = MessageBox.Show("程序已经开启,是否重开程序？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.No)
                    {
                        return;
                    }
                    Process[] p = System.Diagnostics.Process.GetProcessesByName("MainHMI");
                    foreach (var item in p)
                    {
                        item.Kill();
                    }
                    System.Threading.Thread.Sleep(200);
                    Application.Run(new MainForm());
                }
            }
            catch (Exception es)
            {
                MessageBox.Show(es.Message);
            }            
        }
    }
}
